package com.hqd.ch03.v37.core.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

public abstract class AnnotatedElementUtils {
    public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement element, Class<A> annotationType) {
        return element.getAnnotation(annotationType);
    }

    public static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType) {
        for (Annotation annotation : element.getAnnotations()) {
            Class<? extends Annotation> type = annotation.getClass();
            if (type == annotationType || type.getName().equals(annotationType.getName())) {
                return true;
            }
        }
        return false;
    }
}
